/**
 * @file logs.as
 * .
 * @author db0@qq.com
 * @version 1.0.1
 * @date 2013-08-23
 */

package 
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.utils.getTimer;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFormat;

	public class logs extends Sprite
	{
		public static var txt:TextField = new TextField();

		public function logs()
		{
			CONFIG::debugging{
				addChild(txt);
				txt.addEventListener(Event.ADDED_TO_STAGE, init);
			}
		}

		public static function init(e:Event):void
		{
			CONFIG::debugging{
				txt.removeEventListener(Event.ADDED_TO_STAGE, init);
				//txt.filters = [new GlowFilter(0xffffff)];
				/*txt.mouseEnabled = false;*/
				/*txt.selectable = false;*/
				txt.multiline = true;
				txt.textColor = 0xff0000;
				//txt.background = true;
				var txtformat:TextFormat = new TextFormat(null, 20,0x000000);
				txt.defaultTextFormat = txtformat;
				txtformat.underline = true;
				txt.wordWrap = true;
				adds("logs 2017-2-17@author :db0@qq.com");
				txt.scrollV = txt.maxScrollV;
				/*txt.visible=false;*/
				txt.stage.addEventListener(KeyboardEvent.KEY_UP, show);
			}
		}

		static public function show(e:KeyboardEvent):void
		{
			CONFIG::debugging{
				//logs.adds(String.fromCharCode(e.charCode),e.charCode,e.keyCode);
				if(e.ctrlKey && e.shiftKey && e.altKey)
					switch ( String.fromCharCode(e.charCode) )
					{
						case "H":
							txt.visible = !(txt.visible);
							txt.stage.addChild(txt);
							break;
						default :
							break;
					}
			}
		}

		//private static var line:int = 0;

		public static function adds(str:*, ... other):void
		{
			CONFIG::debugging{
				if (txt.stage) {
					txt.stage.addChild(logs.txt);
					txt.width = txt.stage.stageWidth*.5;
					txt.x = txt.width;
					txt.height = txt.stage.stageHeight;
				}

				//txt.appendText("\n" +(++line) + ":" +str);
				//txt.appendText("\n" + String(str));
				txt.appendText("\n" +String(str).replace(/[\r\s\n]/gm," "));
				for each (var item:*in other)
				{
					txt.appendText("," + String(item).replace(/[\r\s\n]/gm," "));
				}

				trace(getTimer(),str, other);
				txt.scrollV = txt.maxScrollV;
			}
		}
	}
}

